<?php
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = 88;

		function do_get()
		{
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );

			$html = load( 'biz.html' );
			$html_data = $html->get( $this->input );
			if ( empty( $html_data ) )
			{
				$this->prompt( '内容不存在', array( array( 'url' => config( 'domain.admin' ) . 'add_html.php?reference=' . urlencode( $url ), 'name' => '创建内容' ), array( 'url' => 'list_html.php', 'name' => '返回列表' ) ) );
				exit;
			}
			$cate_id = $html_data['cate_id'];

			$cate = load( 'biz.cate' );
			$cate_data = $cate->get( array( 'id'=>$cate_id ) );

			if ( ! empty( $cate_data ) )
			{
				//加载基本数据模型
				$module_data = array();
				$html_module = load( 'biz.html_module' );
				$module_data_base = $html_module->base( $this->input );

				//根据栏目类型加载相应的数据模型
				$argument = load( 'biz.argument' );
				switch ( $cate_data['module_type_id'] )
				{
					case $argument->CM_NEWS:
						$module_data_ext = $html_module->news( $this->input );
						$full_html_data = $html->get( $this->input, $argument->content_module[$argument->CM_NEWS] );
						break;

					case $argument->CM_PHOTO:
						$module_data_ext = $html_module->photo( $this->input );
						$full_html_data = $html->get( $this->input, $argument->content_module[$argument->CM_PHOTO] );
						break;

					case $argument->CM_VIDEO:
						$module_data_ext = $html_module->video( $this->input );
						$full_html_data = $html->get( $this->input, $argument->content_module[$argument->CM_VIDEO] );
						break;

						default:
							$module_data_ext = $html_module->news( $this->input );
							$full_html_data = $html->get( $this->input, $argument->content_module[$argument->CM_NEWS] );
				}
				$module_data = array_merge( $module_data_base, $module_data_ext );

				$template->assign( 'module_data', $module_data );
				$template->assign( 'full_html_data', $full_html_data );
			}


			$template->assign( 'current_url', config( 'current_url' ) );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'server.HTTP_REFERER' ) );
			$this->input['cate_id'] = $cate_id;
			$template->appoint( $this->input );
			echo $template->parse( 'set_html.php' );
		}

		/**
		 * description
		 * detail description
		 * @param string user
		 * @param integer id
		 * @return int|string|array|object|mixed
		 */
		function do_post()
		{
			$url = isset( $this->input['reference'] ) ? $this->input['reference'] : config( 'domain.admin' ) . 'list_html.php';
			unset( $this->input['reference'] );

			$html = load( 'biz.html' );
			$result = $html->set( $this->input );

			if ( $result['success'] )
			{
				$this->prompt( '添加成功', array( array( 'url' => config( 'domain.admin' ) . 'set_html.php?id=' . $this->input['id'], 'name' => '继续修改' ), array( 'url' => 'list_html.php', 'name' => '返回列表' ) ) );
			}
			else
			{
				$this->prompt( '添加失败', $this->transform( $result['message'], config( 'server.HTTP_REFERER' ) ) );
			}
		}

		//格式化传入参数
		function format( $value )
		{
			if ( get_magic_quotes_gpc() )
			{
				$value = stripslashes( $value );
			}

			return trim( preg_replace( '/\'/', '\"', $value ) );
		}

	}

	$action = new action();
	$action->run();
?>